<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>学校信息</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
	<style type="text/css">
	    #authority table, caption, tbody, tfoot, thead, tr, th, td{
	        vertical-align: middle;
	    }
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		var h = '85%';
 		if($.browser.msie && $.browser.version == 8.0){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $("#schoolData").omGrid({
        	dataSource : 'schoolData!findAll.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                         {header : '学校名称', name : 'name', width : 150, align : 'center'},
                         {header : '学校ID', name : 'id', width : 100, align : 'center'},
                         {header : '所在区域', name : 'regionalCode', width : 120, align : 'center'} ]
        });
        
        $("#msgReceiverDiv").omDialog({
 		    autoOpen: false,
 		    height: 300,
 		    width : 550,
 		    modal: true,
 		    buttons: [{
 	        text : "取消", 
 	        click : function () {
 	          $("#msgReceiverDiv" ).omDialog("close");
 	      }
 	  	}]
	 	});
        
        $('#schoolAdmin').click(function(){
        	var selects = $("#schoolData").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择学校'});
        		return false;
        	}
			 $('#msgReceiverData').omGrid({
		        	dataSource : 'schoolData!findReceiverAll.do?schoolId='+selects[0].id,
		            height : 280,
		            limit : 10,
		            showIndex : true,
		            colModel : [ 
		                         {header : '姓名', name : 'name', width : 90, align : 'center'},
		                         {header : '手机号码', name : 'phone', width : 140, align : 'center' },
		                         {header : '类别', name : 'type', width : 120, align : 'center',renderer:function(value){
		                             if(value == '0') {
		                            	 return '系统默认';
		                             }else {
		                            	 return '手动添加';
		                             }
		                         }},
		                         {header : '状态', name : 'status', width : 90, align : 'center',renderer:function(value){
		                             if(value == '0') {
		                            	 return '禁用';
		                             }else {
		                            	 return '启用';
		                             }
		                         }}
		                         ]
		        });
		 
		 $("#msgReceiverDiv").omDialog('open');
		 return false;
	 });
        
        $("#msgReceiverEditor").omDialog({
        	autoOpen: false,
  		    height: 300,
  		    width : 450,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#msgReceiverForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#msgReceiverEditor" ).omDialog("close");
              }
          }]
        });
        
        
        $("#receiverAdd").click(function(){
        	var selects = $("#schoolData").omGrid("getSelections",true);
        	$("#msgReceiverForm").resetForm();
        	$("#receiverId").val('');
        	$("#receiverName").val('');
        	$("#receiverPhone").val('');
        	$("#receiverSchoolId").val(selects[0].id);
        	$("#msgReceiverEditor").omDialog("open");
        });
        
        $("#receiverDelete").click(function(){
        	var selects = $("#msgReceiverData").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择删除记录'});
        		return;
        	}
        	if(selects[0].type == '0') {
        		$.omMessageBox.alert({content:'系统默认接收人不能删除'});
        		return;
        	}
        	 $.omMessageBox.confirm({
                 title:'确认删除',
                 content:'您确定删除该数据？',
                 onClose:function(result){
                	 if(result){
                		 $.ajax({
                			 url : 'schoolData!delete.do',
                			 data : {deleteId:selects[0].id},
                			 success : function(data){
                				 if(data == '1'){
                					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
                					 $("#msgReceiverData").omGrid("reload");
                				 }else{
                					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
                				 }
                			 }
                		 });
                	 }
                 }
             });

        	
        });
        
        $("#receiverEditor").click(function(){
        	var selects = $("#msgReceiverData").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择修改记录'});
        		return;
        	}
        	$.ajax({
  			  url: "schoolData!findByID.do",
  			  data : {strategyId : selects[0].id},
  			  dataType : 'json',
  			  success: function(data){
  	        	$("#msgReceiverForm").resetForm();
  	        	$("#receiverId").val(data[0].id);
  	        	$("#receiverName").val(data[0].name);
  	        	$("#receiverPhone").val(data[0].phone);
  			  }
  			});
        	$("#msgReceiverEditor").omDialog("open");
        });
        
        $("#receiverDisable").click(function(){
        	var selects = $("#msgReceiverData").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择禁用记录'});
        		return;
        	}
        	$.omMessageBox.confirm({
                title:'确认禁用',
                content:'您确定禁用该数据？',
                onClose:function(result){
               	 if(result){
               		 $.ajax({
               			 url : 'schoolData!updateStatus.do',
               			 data : {selectedId:selects[0].id,status:0,schoolId:selects[0].schoolId,type:selects[0].type},
               			 success : function(data){
               				 if(data == '1'){
               					 $.omMessageTip.show({timeout : 2000,content : '禁用成功！'});
               					 $("#msgReceiverData").omGrid("reload");
               				 }else if(data == '9'){
               					$.omMessageBox.alert({content:'禁用失败，系统默认接收人至少启用一个！'});
               				 }else{
               					$.omMessageTip.show({timeout : 2000,content : '禁用失败！'});
               				 }
               			 }
               		 });
               	 }
                }
            });
        });
        
        $("#receiverEnable").click(function(){
        	var selects = $("#msgReceiverData").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择启用记录'});
        		return;
        	}
        	$.omMessageBox.confirm({
                title:'确认启用',
                content:'您确定启用该数据？',
                onClose:function(result){
               	 if(result){
               		 $.ajax({
               			 url : 'schoolData!updateStatus.do',
               			 data : {selectedId:selects[0].id,status:1},
               			 success : function(data){
               				 if(data == '1'){
               					 $.omMessageTip.show({timeout : 2000,content : '启用成功！'});
               					 $("#msgReceiverData").omGrid("reload");
               				 }else{
               					 $.omMessageTip.show({timeout : 2000,content : '启用失败！'});
               				 }
               			 }
               		 })
               	 }
                }
            });
        });
        
        $("#updateSchool").click(function(){
        	$.ajax({
	   			 url : 'schoolData!updateSchool.do',
	   			 success : function(data){
	   				 if(data == '1'){
	   					 $.omMessageTip.show({timeout : 2000,content : '同步学校数据成功！'});
	   					 $("#schoolData").omGrid("reload");
	   				 }else{
	   					 $.omMessageTip.show({timeout : 2000,content : '同步学校数据失败！'});
	   				 }
   			 	}
   		 	});
        });
        
        $("#receiverUpdate").click(function(){
        	$.ajax({
	   			 url : 'schoolData!receiverUpdate.do',
	   			 success : function(data){
	   				 if(data == '1'){
	   					 $.omMessageTip.show({timeout : 2000,content : '同步管理员数据成功！'});
	   					 $("#msgReceiverData").omGrid("reload");
	   				 }else{
	   					 $.omMessageTip.show({timeout : 2000,content : '同步管理员数据失败！'});
	   				 }
   			 	}
   		 	});
        });
        
        var alarmOptions  = {
      		  url : 'schoolData!saveReceiver.do',
                success : function(data){
                   	if(data != '0'){  
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                       	$("#msgReceiverEditor").omDialog('close');
                       	$("#msgReceiverData").omGrid("reload");
                   	}else{
                   		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                   	}
                }
      	  };
      	  $("#msgReceiverForm").submit(function() {
                $(this).omAjaxSubmit(alarmOptions);
                return false;//返回false,阻止浏览器默认行为
          });
    });
	</script>  
  </head>
  
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="schoolAdmin"><span><img src="../images/chakan.gif" width="14" height="14" /><ins>学校负责人</ins></span></a>
		         <a href="#" class="rbutton" id="updateSchool"><span><img src="../images/chakan.gif" width="14" height="14" /><ins>同步学校信息</ins></span></a>
	</div>
    <table id="schoolData"></table>
    
   <div id="msgReceiverDiv" title="学校负责人" style="display: none;">
	   <div class="toolbar mar">
			<a href="#" class="rbutton" id="receiverAdd"><span><img src="../images/add.gif" width="14" height="14" /><ins>新增</ins></span></a>
			<a href="#" class="rbutton" id="receiverEditor"><span><img src="../images/add.gif" width="14" height="14" /><ins>修改</ins></span></a>
			<a href="#" class="rbutton" id="receiverDelete"><span><img src="../images/edit.gif" width="14" height="14" /><ins>删除</ins></span></a>
			<a href="#" class="rbutton" id="receiverDisable"><span><img src="../images/red.jpg" width="14" height="14" /><ins>禁用</ins></span></a>
			<a href="#" class="rbutton" id="receiverEnable"><span><img src="../images/green.jpg" width="14" height="14" /><ins>启用</ins></span></a>
			<a href="#" class="rbutton" id="receiverUpdate"><span><img src="../images/green.jpg" width="14" height="14" /><ins>同步信息</ins></span></a>
		</div>
      <table id="msgReceiverData"></table>
   </div>
    <div id="msgReceiverEditor" title="编辑内容" style="display: none;">
     <form id="msgReceiverForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">姓名：</td>
               <td width="28%" colspan="3" align="left">
                 <input type="hidden" id="receiverId" name="msgReceiver.id">
                 <input type="hidden" id="receiverSchoolId" name="msgReceiver.schoolId">
                 <input type="text" id="receiverName" name="msgReceiver.name" class="input_text" />
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">手机号码：</td>
               <td width="28%" colspan="3" align="left">
                   <input type="text" id="receiverPhone" name="msgReceiver.phone" class="input_text" />
               </td>
               </td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
